<?php

include_once($_SERVER["DOCUMENT_ROOT"]. "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"]. "/include/user/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"]. "/include/mblog/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"]. "/include/album/inc.php");
$g_cgival = array();
$g_show = array();
$g_pro = array();

if(! security_check::check_refer())
{
	throw new Exception("来路不明");
}


function check_cgi_pro()
{
	global $g_cgival, $g_show, $g_pro;
	cgi::both($g_cgival['t'],"t","json");
	$g_cgival['t'] = string::un_html($g_cgival['t']);

	cgi::both($g_cgival['callback'], "callback", "");
	$g_cgival['callback'] = string::un_html(string::un_script_code($g_cgival['callback']));
	
	cgi::both($g_cgival['id'],"id",0);
	$g_cgival['id'] = intval($g_cgival['id']);
	
	cgi::both($g_cgival['type'],"type","add");
	
}


function get_data()
{
	global $g_cgival, $g_show, $g_pro;
	
	$id = $g_cgival['id'];
	
	$user_info = new user_info();
	$is_login = $user_info->is_logined();
	if($is_login)
	{
		$user_detail_info = $user_info->get_cur_user_info();
		
		$uid = $user_detail_info["uid"];
		
	}
		
	$db_mblog_video_content = new db_mblog_video_content();
	$db_mblog_pic_content = new db_mblog_pic_content();
	$item = $db_mblog_video_content->get_mblog_video_content_item($id);
	
	$admin_uid = user_info::check_super_admin($uid);
	
	if($item["create_uid"] !=$uid  && !$admin_uid)
	{
		throw new Exception("无权限！");
	}
	
	
	
	if($g_cgival['type'] == "add")
	{
		
		
	}
	elseif($g_cgival['type'] == "del")
	{
		
		$res = $db_mblog_video_content->update_video_info_by_id($id,0);
		
		
	}
	if(!$res)
	{
		throw new Exception("数据操作失败");
	}
	else
	{
		if($item["from"] ==0 )
		{
			$db_user_info = new db_user_info();
			$db_user_info->update_user_count_by_uid($item["create_uid"],"","",-1);
		}
		
		
	}
}

 
try
{
	check_cgi_pro();
	get_data();

	$g_show["error"] = "0";
	$g_show["errmsg"] = "操作成功";
}
catch (Exception $e)
{
	$g_show["error"] = "1";
	$g_show["errmsg"] = $e->getMessage();
}
show_pro();
exit();


function show_pro()
{
	global $g_cgival, $g_pro, $g_show, $config;
	
	if ($g_cgival['t'] == "serialize")
	{
		echo serialize($g_show);
	}
	elseif ($g_cgival['t'] == "json")
	{
		echo output::json("json", $g_show, $g_cgival['callback']);
	}
	elseif($g_cgival['t'] == "jsonp")
	{
		echo output::json("jsonp", $g_show, $g_cgival['callback']);
	}
	elseif($g_cgival['t'] == "perl")
	{
		$string = php_to_perl::php_array_to_perl_hash($g_show);
		$string = mb_convert_encoding($string, "GBK", "UTF-8");
		echo $string;
	}
	elseif($g_cgival['t'] == "iframe")
	{
		header("location:{$g_cgival['link']}");
	}
	else
	{
		
		echo output::json("jsonp", $g_show, $g_cgival['callback']);
	}
}